package com.linjiahao.serviceChat.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linjiahao.commonutils.orderVo.UcenterMember;
import com.linjiahao.serviceChat.client.UCmenberClient;
import com.linjiahao.serviceChat.entiy.FriendsAsk;
import com.linjiahao.serviceChat.mapper.FriendsAskMapper;
import com.linjiahao.serviceChat.service.FriendsAskService;
import com.linjiahao.serviceChat.vo.AddMe_Info;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-10-26
 */
@Service
public class FriendsAskServiceImpl extends ServiceImpl<FriendsAskMapper, FriendsAsk> implements FriendsAskService {

    @Autowired
    UCmenberClient uCmenberClient;

    @Override
    public List<AddMe_Info> getAddMeByList(String id) {
        List<FriendsAsk> friendsAskList = this.baseMapper.selectList(new QueryWrapper<FriendsAsk>().eq("get_id", id));
        if(friendsAskList.size()==0){
            return null;
        }
        List<AddMe_Info> addMe_infoList=new ArrayList<>();
        for (FriendsAsk a:friendsAskList) {
            UcenterMember info = uCmenberClient.getInfo(a.getSendId());
            AddMe_Info addMe_info = new AddMe_Info();
            addMe_info.setHer_id(info.getId());
            addMe_info.setAvatar(info.getAvatar());
            addMe_info.setNickname(info.getNickname());
            addMe_infoList.add(addMe_info);
        }
        return addMe_infoList;
    }

    @Override
    public boolean saveOne(FriendsAsk friendsAsk) {
        FriendsAsk friendsAsk1 = this.baseMapper.selectOne(new QueryWrapper<FriendsAsk>().eq("get_id", friendsAsk.getGetId()).eq("send_id", friendsAsk.getSendId()));
        if(friendsAsk1==null){
            this.baseMapper.insert(friendsAsk);
            return true;
        }
        return false;
    }
}
